<template>
  <Card title="编辑页" :bordered="false" :head-style="headStyle">
    <template #extra>
      <a-button type="primary" @click="handleCreate"> 新增 </a-button>
      <a-button class="ml-2" type="primary" @click="handleEdit"> 编辑 </a-button>
      <a-button class="ml-2" type="primary" @click="handleDelete"> 删除 </a-button>
      <a-button class="ml-2" type="primary" @click="handleOk" :loading="loading"> 保存 </a-button>
    </template>
    <CommonTable ref="commonTableRef" :moduleCode="moduleCode" :formCode="formCode" />
  </Card>
</template>
<script lang="ts" setup>
  import { ref } from 'vue';
  import { Card } from 'ant-design-vue';
  import CommonTable from '../common/index.vue';
  import { headStyle } from '/@/views/pages/managerPage/managerPage.data';
  const props = defineProps({
    formCode: {
      type: String,
      default: '',
    },
    moduleCode: {
      type: String,
      default: '',
    },
  });
  const loading = ref(false);
  const commonTableRef = ref<any>(null);
  const handleCreate = () => {
    commonTableRef.value.handleCreate();
  };
  const handleEdit = () => {
    commonTableRef.value.handleEdit();
  };
  const handleDelete = () => {
    commonTableRef.value.handleDelete();
  };

  //保存
  const handleOk = async () => {
    try {
      loading.value = true;
      await commonTableRef.value.handleOk();
    } catch (error) {
    } finally {
      loading.value = false;
    }
  };
</script>
